class WebPageSafe { //网页基础防护 JS
	constructor(type) {
		if(type){
			this.rightClick()
			this.developerSets()
			this.copyContent()
			this.cutContent()
			this.OpenConsole()
			//this.selectContent()
		}
	}
	
	rightClick(){
		// 禁止右键
		document.oncontextmenu = function (event){
			if(window.event){
				event = window.event;
			}try{
				var the = event.srcElement;
				if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
					return false;
				}
				return false;
			}catch (e){
				return false;
			}
		}
	}
	
	developerSets() {
		// 禁止F12
		document.onkeydown = function(){
			if(window.event && window.event.keyCode == 123) {
				console.log("F12被禁用")
				event.returnValue = false
			}
		}
	}
	
	copyContent() {
		// 屏蔽复制
		document.oncopy = function (event){
			if(window.event){
				event = window.event;
			}try{
				var the = event.srcElement;
				if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
					return false;
				}
				return true;
			}catch (e){
				return false;
			}
		}
	}
	
	cutContent() {
		//屏蔽剪切
		document.oncut = function (event){
			if(window.event){
				event = window.event;
			}try{
				var the = event.srcElement;
				if(!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
					return false;
				}
				return true;
			}catch (e){
				return false;
			}
		}
	}
	OpenConsole(){
		//打开控制台时跳到空白页
		let threshold=160
		window.setInterval(()=>{
			if(window.outerWidth-window.innerWidth>threshold||window.outerHeight-window.innerHeight>threshold){
				location.replace('about:blank')
			}
		},1000)
	}
	/*
	selectContent() {
		//屏蔽选中
		document.onselectstart = function (event){
			if(window.event){
				event = window.event;
			}try{
				var the = event.srcElement;
				if (!((the.tagName == "INPUT" && the.type.toLowerCase() == "text") || the.tagName == "TEXTAREA")){
					return false;
				}
				return true;
			} catch (e) {
				return false;
			}
		}
	}
	*/
}
export default WebPageSafe;